<?php
class Bank_Model_Account
{
    private $_table;
	public function __construct(){
		$this->_table = new Bank_Model_DbTable_Account();
	}


	public function add($row){
		return $this->_table->insert($row);
	}

	public  function update($row,$value,$field='ba_id'){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?",$value);
		return $this->_table->update($row, $where);

	}


	public function delete($value,$field='ba_id'){

		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?", $value);

		return $this->_table->delete($where);

	}


	public function getByValue($value,$field='ba_id'){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,'*');
        $select->where("{$field} = ?",$value);
		return $this->_table->getAdapter()->fetchRow($select);
	}

    public function getByCondition($condition,$type='*',$orderby="",$page=0,$pageSize=0){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
        if(isset($condition["warehouse_id"]) && $condition["warehouse_id"]!=''){
            $select->where(" warehouse_id =?",$condition["warehouse_id"]);
        }
		if(isset($condition["ba_status"]) && $condition["ba_status"]!=''){
            $select->where(" ba_status =?",$condition["ba_status"]);
        }

        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchone($select);
        }else{
			$select->order($orderby);
            if($pageSize>0 && $page>0)
            {
                $start = ($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
		    return $this->_table->getAdapter()->fetchAll($select);
        }
	}
}